package com.googlecode.wicketcharts.showcase.options;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import com.googlecode.wicketcharts.highcharts.options.ChartOptions;
import com.googlecode.wicketcharts.highcharts.options.DummyOption;
import com.googlecode.wicketcharts.highcharts.options.Options;
import com.googlecode.wicketcharts.highcharts.options.PlotOptions;
import com.googlecode.wicketcharts.highcharts.options.PlotOptionsChoice;
import com.googlecode.wicketcharts.highcharts.options.SeriesOptions;
import com.googlecode.wicketcharts.highcharts.options.SeriesType;
import com.googlecode.wicketcharts.highcharts.options.SimpleSeriesOptions;
import com.googlecode.wicketcharts.highcharts.options.Stacking;
import com.googlecode.wicketcharts.highcharts.options.Title;
import com.googlecode.wicketcharts.highcharts.options.XAxis;
import com.googlecode.wicketcharts.highcharts.options.YAxis;

/**
 * Demo of the same stacked and grouped column chart displayed in the Highcharts
 * Demo at <a href=
 * "http://www.highcharts.com/demo/column-stacked-and-grouped">http://www.
 * highcharts.com/demo/column-stacked-and-grouped</a>.
 * 
 * @author Tom Hombergs (tom.hombergs@gmail.com)
 * 
 */
public class StackedAndGroupedColumnChartOptions extends Options {

	private static final long serialVersionUID = 1L;

	public StackedAndGroupedColumnChartOptions() {

		ChartOptions chartOptions = new ChartOptions();
		chartOptions.setType(SeriesType.COLUMN);
		setChartOptions(chartOptions);

		Title title = new Title("Total fruit consumption, grouped by gender");
		setTitle(title);

		XAxis xAxis = new XAxis();
		xAxis.setCategories(Arrays.asList(new String[] { "Apples", "Oranges",
				"Pears", "Grapes", "Bananas" }));
		setxAxis(xAxis);

		YAxis yAxis = new YAxis();
		yAxis.setAllowDecimals(Boolean.FALSE);
		yAxis.setMin(0);
		yAxis.setTitle(new Title("Number of fruits"));
		setyAxis(yAxis);
		
		setTooltip(new DummyOption());

		PlotOptions plotOptions = new PlotOptions();
		plotOptions.setStacking(Stacking.NORMAL);
		PlotOptionsChoice choice = new PlotOptionsChoice();
		choice.setColumn(plotOptions);
		setPlotOptions(choice);

		// create data
		Random r = new Random();
		List<Number> sales = new ArrayList<Number>();
		for (int i = 0; i <= 5; i++) {
			sales.add(r.nextInt(10));
		}
		List<Number> sales2 = new ArrayList<Number>();
		for (int i = 0; i <= 5; i++) {
			sales2.add(r.nextInt(10));
		}
		List<Number> sales3 = new ArrayList<Number>();
		for (int i = 0; i <= 5; i++) {
			sales3.add(r.nextInt(10));
		}
		List<Number> sales4 = new ArrayList<Number>();
		for (int i = 0; i <= 5; i++) {
			sales4.add(r.nextInt(10));
		}

		// add data to the chart
		List<SeriesOptions<Number>> seriesList = new ArrayList<SeriesOptions<Number>>();
		SeriesOptions<Number> series1 = new SimpleSeriesOptions();
		series1.setData(sales);
		series1.setStack("male");
		series1.setName("John");
		seriesList.add(series1);

		SeriesOptions<Number> series2 = new SimpleSeriesOptions();
		series2.setData(sales2);
		series2.setStack("male");
		series2.setName("Joe");
		seriesList.add(series2);
		setSeries(seriesList);

		SeriesOptions<Number> series3 = new SimpleSeriesOptions();
		series3.setData(sales3);
		series3.setStack("female");
		series3.setName("Jane");
		seriesList.add(series3);
		setSeries(seriesList);

		SeriesOptions<Number> series4 = new SimpleSeriesOptions();
		series4.setData(sales4);
		series4.setStack("female");
		series4.setName("Janet");
		seriesList.add(series4);
		setSeries(seriesList);
	}

}
